<template>
	<view class="page">
		<!-- 	<u-navbar title="订单详情" :bgColor="headBackground || 'transparent'" :autoBack="true"
			:titleStyle="{color:pageTitleColor  ||'#fff'}" :leftIconColor="pageTitleColor|| '#fff'" @leftClick="leftClick()">
		</u-navbar> -->

		<view class="page-ctx">
			<view class="box-item box-status flex-between">
				<view class="info-box">
					<view class="title">
						{{info.statusInfo}}
					</view>
					<view class="tip">

					</view>
				</view>
				<view class="icon-box">
					<image v-if="statusInfo == '待支付'" src="@/static/order/status-unpay.png" mode=""></image>
					<image v-if="statusInfo == '无效'" src="@/static/order/status-cancel.png" mode=""></image>
					<image v-if="statusInfo == '订单已取消'" src="@/static/order/status-cancel.png" mode=""></image>
					<image v-if="statusInfo == '待发货'" src="@/static/order/status-unship.png" mode=""></image>
					<image v-if="statusInfo == '待收货'" src="@/static/order/status-unreceive.png" mode=""></image>
					<image v-if="statusInfo == '待评价' && info.ifComment!=1" src="@/static/order/status-unreview.png" mode="">
					</image>
					<image v-if="(statusInfo == '已完成') || (info.orderStatus == 4 && info.ifComment == 1)"
						src="@/static/order/status-used.png" mode=""></image>
				</view>
			</view>


			<view class="box-item box-info">
				<view class="info-title">
					收货人信息
				</view>
				<view class="order-content">
					<view class="item">
						<text class="label"> 收货人：</text>
						<text class="value">{{shouhuoInfo.name}} {{shouhuoInfo.phone}}</text>
					</view>
					<view class="item">
						<text class="label">收货地址：</text>
						<text class="value">{{shouhuoInfo.address}}</text>
					</view>
				</view>
			</view>

			<view class="box-item box-info">
				<view class="info-title">
					商品详情
				</view>
				<view class="products-wrap">
					<view class="product-list">
						<view class="product-item flex" v-for="(product_item,index) in products" :key="index">
							<view class="poster-box">
								<image :src="product_item.image" mode="aspectFill"></image>
							</view>
							<view class="info">
								<view class="title-box">
									<view class="title">
										{{product_item.title}}
									</view>
								</view>
								<view class="desc-box">
									<view class="desc ellipsis-1">
										{{product_item.keyVals }}
									</view>
								</view>
								<view class="price-box flex-between">
									<view class="price-info">
										<!-- <text class="huobi">￥</text> -->
										<text class="price">{{product_item.jifen || 0}}积分</text>
										<text class="unit" v-if="product_item.unit">/{{product_item.unit}}</text>
									</view>
									<text class="num">x {{product_item.num}}</text>
								</view>
								<!-- <view class="product-reviews-box" v-if="info.orderStatus == 5 && product_item.ifComment == 0">
									<view class="btns">
										<view class="btn fit-text btn-reviews" @click.stop="toReview(product_item)">
											写评价
										</view>
									</view>
								</view>-->
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="box-item box-price">
				<div class="mingxi-title">
					价格明细
				</div>
				<view class="mingxi-list">
					<view class="mingxi-item flex-between">
						<view class="label">
							商品总价
						</view>
						<view class="num">
							共{{total_product_number}}件商品
						</view>
						<view class="value">
							{{total_jifen}} 积分
						</view>
					</view>

					<!-- <view class="mingxi-item flex-between">
						<view class="label">
							配送费
						</view>
						<view class="num">
							
						</view>
						<view class="value">
							{{order_yunfei ? '￥' + order_yunfei:  '免运费' }}
						</view>
					</view> -->
				</view>

				<view class="total-info flex-between">
					<view class="label">
						合计应付
					</view>
					<view class="value">
						{{total_jifen}} 积分
					</view>
				</view>
			</view>

			<!-- <view class="box-item box-pay" >
				<view class="pay-info flex-between">
					<text class="label">支付方式：</text>
					<text class="value flex">
						<image src="@/static/points/type-jifen.png" mode=""></image>
						<text>积分支付</text>
					</text>
				</view>
			</view> -->

			<view class="box-item box-info">
				<view class="info-title">
					订单信息
				</view>
				<view class="order-content">
					<view class="item">
						<text class="label"> 订单编号：</text>
						<text class="value">{{info.orderNo}}</text>
					</view>
					<view class="item">
						<text class="label">下单时间：</text>
						<text class="value">{{info.createdTime}}</text>
					</view>
					<view class="item">
						<text class="label">支付方式：</text>
						<text class="value">积分兑换</text>
					</view>
					<view class="item">
						<text class="label">配送方式：</text>
						<text class="value">普通快递</text>
					</view>
					<view class="item">
						<text class="label">订单备注：</text>
						<text class="value">{{info.remark}}</text>
					</view>
				</view>
			</view>

			<view class="box-item box-info" v-if="fahuoInfo.id">
				<view class="info-title">
					物流信息
				</view>
				<view class="order-content">
					<view class="item">
						<text class="label"> 物流单号：</text>
						<text class="value">{{fahuoInfo.expressOrder}}</text>
					</view>
					<view class="item">
						<text class="label">承运物流：</text>
						<text class="value">{{fahuoInfo.expressName}}</text>
					</view>

					<view class="item" v-if="express">
						<text class="label">物流进度：</text>
						<text class="value"></text>
					</view>

					<view class="express-info" v-if="express">
						<view class="express-content" v-if="express.Traces && express.Traces.length>0">
							<u-steps activeColor="#84C547" :current="express.length" direction="column" dot>
								<u-steps-item :title="item.AcceptStation" :desc="item.AcceptTime" v-for="(item,index) in express.Traces"
									:key="index">
								</u-steps-item>
							</u-steps>
						</view>
						<view class="express-reason" v-if="express.Reason">
							<text class="">{{express.Reason || ''}}</text>
						</view>
					</view>
				</view>
			</view>

		</view>

		<w_bottom_safe height="140" />


		<view class="page-foot" v-if="info.ifReceive == 1 ">
			<view class="safe-fixed-bottom">
				<view class="btns flex-between">
					<view v-if="info.ifReceive == 1" class="btn fit-text btn-pay" @click="doReceive()">
						确认收货
					</view>
				</view>
			</view>
		</view>


		<order_receive_pop data-title="订单确认收货" ref="order_receive_pop" @confirm="update_order_info" />

	</view>
</template>

<script>
	import order_receive_pop from '@/components/order/order_receive_pop.vue'
	export default {
		components: {
			order_receive_pop,
		},
		data() {
			return {
				is_test_hexiao: true, // 测试被核销

				total_jifen: 0,

				//
				from: '',
				id: '',
				order_id: '',
				info: {},
				statusInfo: '',
				payInfo: {},
				shouhuoInfo: {
					name: '',
					phone: '',
					address: '',
				}, //收货人信息
				fahuoInfo: {}, //发货信息
				offlineJson: [],
				total_product_number: 0,
				products: [],
				full_receive_address: '',
				//
				order_yunfei: '',


				//
				order_zhekou_bili: 10, //打几折
				order_zhekou_price: 0,
				//
				order_points_dixian_price: 0, //积分抵现金额
				order_points_dixian_number: 0, //使用积分数量

				//
				express: '',
				index_config: [],
				xindanshijian: '',
				xindanshijian1: '',
				expressInfo: [{
					name: '下单'
				}, {
					name: '出库'
				}, {
					name: '运输'
				}, {
					name: '签收'
				}],

				//
				statusEn: '', // unpay 
				statusEnMap: {
					'-5': 'unpay',
					'-5_2': 'invalid',
					'-1': 'canceled',
					2: 'unship',
					3: 'unreceive',
					4: 'unreview',
					5: 'finish',
				},

				//
				headBackground: '', //控制顶部标题栏颜色 默认透明颜色 transparent
				statusBackgroundMap: {
					1: "#F64A48",
					2: "#4EC2FF",
					3: "#EEEEEE",
					'-1': "#EEEEEE",
				},
				//
				pageTitleColor: '#000000',
				statusTitleColorMap: {
					1: "#ffffff",
					2: "#ffffff",
					3: "#000000",
					'-1': "#000000",
				},


				//结果类状态
				is_finish_pay: false, //是否已被支付
				is_xianxia: false, //是否线下支付
				//
				pay_end_time: 0, //支付倒计时
				receive_end_time: '', //确认收货倒计时
			}
		},

		computed: {

		},

		onLoad(option) {
			this.from = option.from || ''; // payment 支付结果
			this.id = option.id;
			this.order_id = option.id;
		},
		onShow() {
			this.setView();
		},
		onHide() {},
		onPullDownRefresh() {

		},
		onPageScroll(e) {
			if (e.scrollTop > 80) {
				this.headBackground = this.statusBackgroundMap[this.info.status]
			} else {
				this.headBackground = ''
			}
		},
		methods: {
			leftClick() {
				console.log('leftClick')
				if (this.from == 'payment') {
					this.toRoute('/my')
				} else {
					this.toBack()
				}
			},

			setView() {
				this.showLoading({
					title: '订单信息查询中'
				})

				this.$api({
					url: '/service.php',
					method: 'get',
					data: {
						action: 'orders_detail',
						id: this.id
					},
				}).then(res => {
					if (res.code == 200) {

						let data = res.data;

						this.info = data;
						this.statusInfo = data.statusInfo || ''
						let {
							payInfo,
							products,
							shouhuoInfo,
							fahuoInfo,
							offlineJson
						} = data;


						//金额信息
						this.payInfo = payInfo;

						//商品
						this.products = products;
						this.products.forEach((v) => {
							this.total_product_number += parseInt(v.num)
							this.total_jifen += parseFloat(v.jifen)
						})
						this.total_jifen = this.total_jifen.toFixed(2)

						//线下支付
						this.offlineJson = offlineJson || [];
						this.is_xianxia = this.offlineJson.length > 0
						if (this.is_xianxia) {
							this.uploadImages = offlineJson[0].images.split(',')
						}
						//收货信息
						this.shouhuoInfo = shouhuoInfo;
						if (shouhuoInfo) {
							let {
								country,
								province,
								city,
								area,
								address
							} = shouhuoInfo;
							this.full_receive_address = [country, province, city, area, address].filter(v => v).join(' ')
						}

						//发货信息
						this.fahuoInfo = fahuoInfo;
						this.is_finish_pay = parseFloat(data.pricePayed) > 0;
						//

						// 订单状态
						let orderStatus = data.orderStatus;
						this.statusEn = this.statusEnMap[orderStatus]
						this.pageTitleColor = this.statusTitleColorMap[orderStatus]

						if (data.orderStatus >= 3) { //待收货 3
							this.express_getInfo(this.fahuoInfo.id)
						}
					}
				})
			},


			//快递物流信息
			express_getInfo(fahuo_id) {
				this.$api({
					url: '/service.php',
					method: 'get',
					data: {
						action: 'express_getInfo',
						fahuo_id: fahuo_id
					},
				}).then(res => {
					this.express = res.data
				})
			},

			doReceive() {
				this.$refs.order_receive_pop.init(this.info)
			},

			update_order_info() {
				this.setView()
			},

			toReview(product) {
				this.toRoute({
					path: '/order-review-submit',
					query: {
						orderId: this.order_id,
						inventoryId: item.id
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F8F8F8;
	}
</style>

<style lang="scss" scoped>
	.page-ctx {
		padding: 24rpx 32rpx;
	}

	.box-item {
		margin-bottom: 24rpx;
		padding: 32rpx 24rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 16rpx 2rpx rgba(0, 0, 0, 0.08);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.box-status {
		.info-box {
			flex: 1;
			overflow: hidden;


			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #000000;
			}

			.tip {
				margin-top: 12rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 20rpx;
				color: #B3B9C9;

				.tip-item {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 20rpx;
					color: #B3B9C9;
				}
			}
		}

		.icon-box {
			width: 72rpx;
			height: 72rpx;

			image {
				width: 72rpx;
				height: 72rpx;
			}
		}
	}




	.products-wrap {
		padding: 0 0;

		.product-list {
			.product-item {
				padding: 32rpx 0;
				align-items: flex-start;

				&+.product-item {
					border-top: 1rpx solid #eee;
				}

				.poster-box {
					width: 176rpx;
					height: 176rpx;
					border-radius: 8rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.info {
					flex: 1;
					overflow: hidden;
					padding-left: 32rpx;



					.title-box {}

					.title {
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 28rpx;
						color: #222222;
						line-height: 1.5;
					}

					.desc-box {
						margin-top: 14rpx;

						.desc {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #B3B9C9;
						}
					}


					.price-box {
						margin-top: 24rpx;

						.price-info {
							.huobi {
								font-family: PingFang SC, PingFang SC;
								font-weight: bold;
								font-size: 20rpx;
								color: #000000;
							}

							.price {
								font-family: PingFang SC, PingFang SC;
								font-weight: bold;
								font-size: 28rpx;
								color: #000000;
							}

							.unit {
								font-family: PingFang SC, PingFang SC;
								font-weight: bold;
								font-size: 20rpx;
								color: #000000;
							}
						}

						.num {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 24rpx;
							color: #000000;
						}

					}
				}
			}

		}

	}




	// 产品评价
	.product-reviews-box {
		margin-top: 24rpx;
		display: flex;
		justify-content: flex-end;

		.btns {
			flex: 1;
			display: flex;
			justify-content: flex-end;
			overflow: hidden;
			flex-wrap: wrap;

			.btn {
				margin-left: 20rpx;
				min-width: 136rpx;
				height: 48rpx;
				background: #F4F4F4;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #666666;

				&.btn-reviews {
					background: #CB0011;
					color: #FFFFFF;
				}
			}
		}
	}








	.cell-item {
		height: 108rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		&+.cell-item {
			border-top: 1rpx solid #EAEAEA;
		}

		.label {
			padding-right: 24rpx;
			flex: 1;
			overflow: hidden;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;

			image {
				margin-right: 10rpx;
				width: 48rpx;
				height: 48rpx;
				border-radius: 8rpx;
			}

			text {
				flex: 1;
				overflow: hidden;
			}
		}

		.value-box {
			width: fit-content;

			.value {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #7D7D7D;

				&.right-padding {
					margin-right: 10rpx;
				}
			}

			image {
				width: 30rpx;
				height: 30rpx;
			}
		}
	}



	.box-price {
		margin-top: 24rpx;

		.mingxi-title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #222222;
		}

		.mingxi-list {}

		.mingxi-item {
			margin-top: 20rpx;

			.label {
				width: 160rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #222222;
			}

			.num {
				flex: 1;
				text-align: left;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #B3B9C9;
			}

			.value {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #222222;
			}
		}

		.total-info {
			border-top: 1rpx solid #F8F8F8;
			margin-top: 32rpx;
			padding-top: 32rpx;

			.label {
				font-family: PingFang SC, PingFang SC;
				font-weight: 800;
				font-size: 28rpx;
				color: #222222;
			}

			.value {
				font-family: PingFang SC, PingFang SC;
				font-weight: 800;
				font-size: 28rpx;
				color: #000000;
			}
		}

	}





	.box-pay {
		padding: 24rpx 24rpx;

		.pay-info {
			.label {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #222222;
			}

			.value {

				image {
					margin-right: 24rpx;
					width: 40rpx;
					height: 40rpx;
				}

				text {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #000000;
				}
			}
		}
	}

	.box-info {
		.info-title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #222222;
		}

		.order-content {
			margin-top: 20rpx;

			.item {
				display: flex;

				&+.item {
					margin-top: 22rpx;
				}

				.label {
					display: inline-block;
					min-width: 5em;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 24rpx;
					color: #222222;
				}

				.value {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #222222;
				}
			}
		}
	}





	// 快递信息
	.express-reason {
		margin-top: 10rpx;
		font-size: 24rpx;
	}





	.page-foot {

		.btns {
			width: 100%;

			.btn {
				flex: 1;
				// width: 345rpx;
				height: 80rpx;
				border-radius: 58rpx 58rpx 58rpx 58rpx;
				border: 2rpx solid #EFF1F6;
				font-family: Microsoft YaHei, Microsoft YaHei;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;


				&+.btn {
					margin-left: 24rpx;
				}

				&.btn-pay {
					background: #CB0011;
					color: #FFFFFF;
				}


				&.btn-cancel {}

				&.btn-refund {}

				&.btn-disabled {}

				&[disabled] {}


			}
		}

	}
</style>